<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闭包面试题</title>
    <script>
        var name = 'the window'
        
        var object = {
            name:'my object',
            getName:function () {
                return function () {
                    return this.name
                }
            }
        }

        // the window ，调用者是window,无闭包，内部函数没有引用外部函数的变量
        console.log(object.getName()()) 
        
        //
        
        var title = 'the window'
        var obj = {
            name:'my object',
            getName:function () {
                var that = this
                return function () {
                    return that.name
                }
            }
        }

        // my object,obj是调用者，产生闭包
        console.log(obj.getName()())

        /**
         * 面试题
         */
        function fun(n, o) {
            console.log(o)
            return {
                fun:function (m) {
                    return fun(m, n)
                }
            }
        }
        
        var a = fun(0);
        a.fun(1)
        a.fun(2)
        a.fun(3)
        
        var b = fun(0).fun(1).fun(2).fun(3)
        var c = fun(0).fun(1);
        
        c.fun(2)
        c.fun(3)
    </script>
</head>
<body>

</body>
</html>
